<!--
* description: 旧件管理-现调通知查询
* author: wangjuan
* createdDate: 2021-4-15
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-more-btn="true"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible.sync="editPopupsVisible"
      :popups-state="editPopupsState"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import api from '@/api/se/coreManagement'

export default {
  name: 'CurrentNoticeReplay',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      editRowData: {},
      pupsVisible: false,
      // 网格查询API配置对象
      apiConfig: api.investigateNoticeList,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'),
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey3',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right'
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '通知编号：',
              codeField: 'notifyCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '通知日期：',
              codeField: 'notifyDateStart,notifyDateEnd',
              component: () =>
                import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '通知发布人：',
              codeField: 'empname',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '发布人电话：',
              codeField: 'mobile',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '状态：',
              codeField: 'status',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'status,statusName',
              options: [
                { status: '0', statusName: '已发布' },
                { status: '1', statusName: '已回复' }
              ],
              type: 'dropdownList',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey6',
              labelName: '回复日期：',
              codeField: 'repleyDateStart,repleyDateEnd',
              component: () =>
                import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey7',
              labelName: '反馈截止日期：',
              codeField: 'limitDateStart,limitDateEnd',
              component: () =>
                import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMul: false,
              isMust: false
            }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'controlBtn1',
              label: '操作',
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '详情',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.edit(index)
                }
              ]
            },
            {
              prop: 'notifyCode',
              label: '通知编号',
              width: 140
            },
            {
              prop: 'notifyDate',
              label: '通知时间',
              width: 140
            },
            {
              prop: 'empname',
              label: '通知发布人'
            },
            {
              prop: 'mobile',
              label: '发布人电话',
              width: 140
            },
            {
              prop: 'dlrCode',
              label: '门店编码',
              width: 140
            },
            {
              prop: 'dlrName',
              label: '门店名称'
            },
            {
              prop: 'status',
              label: '状态'
            },
            {
              prop: 'repleyDate',
              label: '回复日期',
              width: 140
            },
            {
              prop: 'limitDate',
              label: '反馈截至日期',
              width: 140
            }
          ],

      // 表单查询数据
      formField: this.$utils.getFormField(
        this,
        {
          notifyCode: '',
          preAuthorCode: '',
          vin: '',
          status: '',
          notifyDateStart: '',
          notifyDateEnd: '',
          repleyDateStart: '',
          repleyDateEnd: '',
          limitDateStart: '',
          limitDateEnd: '',
          empname: '',
          mobile: ''
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    }
  },

  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
    // 获取数据
    edit(index) {
      const queryObj = {
        // 保存mutation
        type: 'mutation',
        // api配置
        apiConfig: api.investigateNoticeDetails,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          notifyCode: this.$refs['multipleTable'].list[index].notifyCode
        }
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then((response) => {
        if (response.result === '1') {
          this.editRowData = Object.assign(
            {},
            response.rows[0],
            this.$refs['multipleTable'].list[index]
          )
          this.editPopupsVisible = true
          this.editPopupsState = 'edit'
        }
      })
    }
  }
}
</script>
